{% import "macros/public-draft.html" as public_draft %}

{% if section and section.title %}
{% set page_title = "Ranim: " ~ section.title %}
{% elif page and page.title %}
{% set page_title = "Ranim: " ~ page.title %}
{% else %}
{% set page_title = "Ranim" %}
{% endif %}

{% set_global root_section = get_section(path="_index.md") %}

{# Shortcut to get the section/page. This variable will have a value except in some special pages like `404.html`. #}
{% set_global section_or_page = false %}
{% if section or page %}
{% set_global section_or_page = section | default(value=page) %}
{% endif %}

<!DOCTYPE html>
<html lang="{{ lang }}" class="{% block theme %}{% endblock %}">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  {# TODO: og metas #}

  <link rel="stylesheet" href="{{ get_url(path='index.css') }}">
  <link rel="stylesheet" href="{{ get_url(path='github-markdown.css') }}">

  <!-- Favicon -->
  <link rel="apple-touch-icon" sizes="180x180" href="{{ get_url(path='apple-touch-icon.png') }}">
  <link rel="icon" type="image/png" sizes="32x32" href="{{ get_url(path='favicon-32x32.png') }}">
  <link rel="icon" type="image/png" sizes="16x16" href="{{ get_url(path='favicon-16x16.png') }}">
  <link rel="manifest" href="{{ get_url(path='site.webmanifest') }}">

  <!-- Shoelace -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/themes/light.css" />
  <script type="module"
    src="https://cdn.jsdelivr.net/npm/@shoelace-style/shoelace@2.20.1/cdn/shoelace-autoloader.js"></script>

  <!-- TODO: feed -->
  <!-- {% if config.generate_feed %}
    <link rel="alternate"
      type={% if config.feed_filename == "atom.xml" %}"application/atom+xml"{% else %}"application/rss+xml"{% endif %}
      title="RSS" href="{{ get_url(path=config.feed_filename) | safe }}">
    {% endif %} -->

  <title>{% if page.extra.public_draft or section.extra.public_draft %}[DRAFT] {% endif %}{{ page_title }}</title>
  {% block head_extensions %}{% endblock head_extensions %}
</head>

<body class="layout">
  <header class="layout__header">
    <div class="back"></div>
    <nav class="nav">
      <a href="{{ get_url(path='/') }}" class="home nav-btn">
        <img src="{{ get_url(path='ranim.png') }}" alt="Ranim Icon" />
        <span>Ranim</span>
      </a>
      <a href="{{ get_url(path='book', trailing_slash=true) }}" class="section-btn nav-btn" rel="noopener noreferer" target="_blank">
        指南
        <svg xmlns="http://www.w3.org/2000/svg" style="padding: 0 2px;" width="12" height="12"
          viewBox="0 0 24 24"><!-- Icon from Material Symbols by Google - https://github.com/google/material-design-icons/blob/master/LICENSE -->
          <path fill="currentColor"
            d="M5 21q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h7v2H5v14h14v-7h2v7q0 .825-.587 1.413T19 21zm4.7-5.3l-1.4-1.4L17.6 5H14V3h7v7h-2V6.4z" />
        </svg>
        </div>
        <a href="{{ get_url(path='doc/ranim', trailing_slash=true) }}" class="section-btn nav-btn" rel="noopener noreferer" target="_blank">
          文档
          <svg xmlns="http://www.w3.org/2000/svg" style="padding: 0 2px;" width="12" height="12"
            viewBox="0 0 24 24"><!-- Icon from Material Symbols by Google - https://github.com/google/material-design-icons/blob/master/LICENSE -->
            <path fill="currentColor"
              d="M5 21q-.825 0-1.412-.587T3 19V5q0-.825.588-1.412T5 3h7v2H5v14h14v-7h2v7q0 .825-.587 1.413T19 21zm4.7-5.3l-1.4-1.4L17.6 5H14V3h7v7h-2V6.4z" />
          </svg>
        </a>
        {% for path in root_section.subsections %}
        {% set subsection = get_section(path=path) %}
        <a href="{{subsection.permalink}}" class="section-btn nav-btn">
          {{ subsection.title }}
        </a>
        {% endfor %}
        <a href="https://github.com/AzurIce/ranim" target="_blank" rel="noreferrer" class="icon-btn nav-btn">
          <svg width="24" height="24" fill="currentColor" viewBox="3 3 18 18">
            <title>GitHub</title>
            <path
              d="M12 3C7.0275 3 3 7.12937 3 12.2276C3 16.3109 5.57625 19.7597 9.15374 20.9824C9.60374 21.0631 9.77249 20.7863 9.77249 20.5441C9.77249 20.3249 9.76125 19.5982 9.76125 18.8254C7.5 19.2522 6.915 18.2602 6.735 17.7412C6.63375 17.4759 6.19499 16.6569 5.8125 16.4378C5.4975 16.2647 5.0475 15.838 5.80124 15.8264C6.51 15.8149 7.01625 16.4954 7.18499 16.7723C7.99499 18.1679 9.28875 17.7758 9.80625 17.5335C9.885 16.9337 10.1212 16.53 10.38 16.2993C8.3775 16.0687 6.285 15.2728 6.285 11.7432C6.285 10.7397 6.63375 9.9092 7.20749 9.26326C7.1175 9.03257 6.8025 8.08674 7.2975 6.81794C7.2975 6.81794 8.05125 6.57571 9.77249 7.76377C10.4925 7.55615 11.2575 7.45234 12.0225 7.45234C12.7875 7.45234 13.5525 7.55615 14.2725 7.76377C15.9937 6.56418 16.7475 6.81794 16.7475 6.81794C17.2424 8.08674 16.9275 9.03257 16.8375 9.26326C17.4113 9.9092 17.76 10.7281 17.76 11.7432C17.76 15.2843 15.6563 16.0687 13.6537 16.2993C13.98 16.5877 14.2613 17.1414 14.2613 18.0065C14.2613 19.2407 14.25 20.2326 14.25 20.5441C14.25 20.7863 14.4188 21.0746 14.8688 20.9824C16.6554 20.364 18.2079 19.1866 19.3078 17.6162C20.4077 16.0457 20.9995 14.1611 21 12.2276C21 7.12937 16.9725 3 12 3Z">
            </path>
          </svg>
        </a>
    </nav>
  </header>

  <main class="layout__body">
    {% block main %}
    {% endblock main %}
  </main>
</body>

</html>